package com.example.a22310.myapplication.ViewModel.Train;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.example.a22310.myapplication.Beans.NewBean;
import com.example.a22310.myapplication.Listener.ClubListener;
import com.example.a22310.myapplication.Model.TrainModel;

public class AddNewsViewModel implements ClubListener<NewBean> {
    private ActivityConsultBinding binding;
    private AppCompatActivity activity;
    private NewBean newBean;
    private int club_id,user_id;

    public AddNewsViewModel(AppCompatActivity activity, ActivityConsultBinding binding,int club_id,int user_id){
        this.activity = activity;
        this.binding = binding;
        this.club_id = club_id;
        this.user_id = user_id;
        binding.setAdd(this);
    }

    public void send_news(View view) {  //发送消息
        newBean=new NewBean();
        newBean.setClub_id(club_id);
        newBean.setSend_id(user_id);
        newBean.setContent(binding.edContent.getText().toString());
        TrainModel trainModel=new TrainModel();
        trainModel.addNews(newBean,AddNewsViewModel.this);
    }

    @Override
    public void onSuccess(NewBean newBean) {
        if(newBean.getSuccess()==1){
            CHECK_NEWS_SEND_NUMBER = 1;
            binding.edContent.setText("");
            Toast.makeText(activity,"发送成功",Toast.LENGTH_LONG).show();
        }
        else
            Toast.makeText(activity,"发送超时",Toast.LENGTH_LONG).show();

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败",Toast.LENGTH_LONG).show();
    }}
